﻿using UnityEngine;
using System.Collections;

public enum State
{
    normal = 0,
    to,
    to2,
    top,
    down,
    down2,
    normal2
}
public class mEntitiy : MonoBehaviour 
{
    public AnimationCurve localEulerX;
    public AnimationCurve localPosZ;
    //public float localEnlerX_min = -50;
    //public float localEnlerX_max = 50;

    private Vector3 initLocalPos;
    
	void Awake()
    {
        Key_Frame();

        initLocalPos = transform.localPosition;
    }
    public void Smaple(float factor)
    {
        if (factor < 0 || factor > 1) Debug.LogError("this ?!" + factor);
        //transform.localRotation = Quaternion.Euler(Vector3.zero + Vector3.right * Mathf.Lerp(localEnlerX_min, localEnlerX_max, factor));
        transform.localRotation = Quaternion.Euler(Vector3.zero + Vector3.right * localEulerX.Evaluate(factor));
        Debug.Log(transform.name + ":" + initLocalPos);
        transform.localPosition = initLocalPos + Vector3.forward * localPosZ.Evaluate(factor);
    }

    [ContextMenu("Key Frame")]
    public void Key_Frame()
    {
        localEulerX = new AnimationCurve();
        localEulerX.AddKey(0.166667f * 0, 0f);
        localEulerX.AddKey(0.166667f * 1, -50f);
        localEulerX.AddKey(0.166667f * 2, -30f);
        localEulerX.AddKey(0.166667f * 3, 0f);
        localEulerX.AddKey(0.166667f * 4, 30f);
        localEulerX.AddKey(0.166667f * 5, 50f);
        localEulerX.AddKey(1.0f, 0f);

        localPosZ = new AnimationCurve();
        localPosZ.AddKey(0.166667f * 0, 130f);
        localPosZ.AddKey(0.166667f * 1, 100f);
        localPosZ.AddKey(0.166667f * 2, 25f);
        localPosZ.AddKey(0.166667f * 3, 0f);
        localPosZ.AddKey(0.166667f * 4, 25f);
        localPosZ.AddKey(0.166667f * 5, 100f);
        localPosZ.AddKey(1.0f, 130f);
    }
}
